#ifndef SLIDER_H
#define SLIDER_H

#include "widget.h"
#include "../../anime/utils.h"

#include <QColor>
#include <QPixmap>
#include <QPainterPath>
#include <QList>

class Slider;

class SliderListener
{
public:
    virtual void OnPosChanged( Slider* sender, double newPos ) = 0;
    virtual void OnClickOrOnEndDrag( Slider* sender, double newPos ) = 0;
    virtual void OnStartDrag( Slider* slider ) = 0;
};

class Slider: public Widget,
              private AnimationObserver
{

public:

    // constructor and destructor
    Slider( Widget* _parent, Engine* _engine, int _x, int _y, int _w, int _h,
            const QColor& _minColor = QColor( 255, 0, 0, 100 ),
            const QColor& _maxColor = QColor( 255, 255, 0, 100 ),
            const QColor& _ballColor = QColor( 255, 0, 0, 150 ) );
    ~Slider();

    void SetPosition( double newPos );

    // paint function
    virtual void Paint( QPainter &painter );

    // listeners handling
    void AddSliderListener( SliderListener* sl );

    // mouse handling
    virtual void OnMousePressed( QMouseEvent *e, bool inside, int x_rel, int y_rel );
    virtual void OnMouseReleased( QMouseEvent *e, bool inside, int x_rel, int y_rel );
    virtual void OnMouseMoved( QMouseEvent *e, bool onWidget, int x_rel, int y_rel );

protected:

    virtual void doShow();
    virtual void doHide();
    Animation* showAnime;
    IntGraph showGraph;
    int showWidth;

    double pos;
    int range;
    int ballRadius;
    QRect* innerBallRect;
    QRect* sliderRect;
    int h2;
    int h4;

    QBrush* sliderBrush;
    QBrush* ballBrush;
    QPixmap* sliderPixmap;

    int ballGradientRadius;
    IntGraph animeGraph;
    OneMinus_NI< float >* om_ni;
    Animation* ballPulse;
    bool onBall;

    bool dragging;
    int prevX;
    double prevPos;

    QList< SliderListener* > listeners;

    // AnimationObserver implementation
    virtual void OnPause(Animation* a);
    virtual void OnStop(Animation* a);
    virtual void OnEnd(Animation* a);
    virtual void OnPlay(Animation* a);
};

#endif // SLIDER_H
